/* GUI CONVERTED from rcshipdt.p (converter v1.75) Mon Nov 20 16:58:08 2000 */
/* rcshipdt.p - Release Management Customer Schedules                   */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                   */
/* REVISION: 7.0    LAST MODIFIED: 01/29/92           BY: WUG *F110*    */
/* REVISION: 7.0    LAST MODIFIED: 03/26/92           BY: WUG *F323*    */
/* REVISION: 7.3    LAST MODIFIED: 12/18/92           BY: WUG *G462*    */
/* REVISION: 7.3    LAST MODIFIED: 11/18/94           BY: WUG *FT88*    */
/* REVISION: 7.4    LAST MODIFIED: 05/16/97   BY: *H0Z5* Aruna Patil    */
/* REVISION: 8.6E   LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane      */
/* REVISION: 8.6E   LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan     */
/* REVISION: 8.6E   LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan     */
/* REVISION: 9.1    LAST MODIFIED: 04/11/00   BY: *J3PK* Reetu Kapoor   */
/* REVISION: 9.1    LAST MODIFIED: 08/23/00   BY: *N0ND* Mark Brown     */
/* REVISION: 9.1    LAST MODIFIED: 09/06/00   BY: *N0RG* BalbeerS Rajput*/

        /* CALCULATES SHIP/ARRIVE DATES
           BASED ON SHIPFROM/TO CALENDARS, TRANSP LEADTIME */


/* ********** Begin Translatable Strings Definitions ********* */

/*N0RG*
 * &SCOPED-DEFINE rcshipdt_p_1 "Unable to find matching ship-from/ship-to operating days"
 * /* MaxLen: Comment: */
 *N0RG*/

/* ********** End Translatable Strings Definitions ********* */

/*N0RG*/ {mfdeclre.i}
/*N0RG*/ {gplabel.i}

         define input parameter  shipfrom_site      as character.
         define input parameter  shipto_site        as character.
         define input parameter  due_date           as date.
         define input parameter  due_time           as character.
         define input parameter  transport_lt       as decimal.

         define output parameter ship_date          as date.
         define output parameter ship_time          as character.
         define output parameter arrive_date        as date.
         define output parameter arrive_time        as character.
         define output parameter ret_status         as character.

         define        variable  start_date         as date.
         define        variable  shipfrom_date      as date.
         define        variable  shipto_date        as date.
         define        variable  i                  as integer.
/*J3PK*/ define        variable  l_temp_date        as date          no-undo.
/*J3PK*/ define        variable  l_transport_lt     as decimal       no-undo.
/*J3PK*/ define shared variable  l_inc_wkend_shpcal like so_incl_iss no-undo.

     /* BACKWARD-ADJUST DATES PER TRADING PARTNER OPERATING  DAYS  AND
        TRANSPORTATION  LEADTIME.  KEEP DOING IT UNTIL WE HIT A DAY WHERE
        BOTH SHIPFROM AND SHIPTO ARE OPERATING, OR WE LOOKED BACK  UP  TO
        14  DAYS.   IT  WOULD  BE  GREAT  IF  WE  COULD  ADJUST DATE/TIME
        TOGETHER, EXCEPT THAT THE SITE OPERATING SCHEDULE ISN'T  COMPLETE
        DESCRIBED IN MFG/PRO.  WE KNOW HOW MANY HOURS THERE ARE AVAILABLE
        DURING THE DAY BUT NOT WHAT TIME OF THE DAY THEY ARE.  ANYWAY ITS
        NOT TOO BIG A DEAL YET SINCE MRP ONLY IS IN TERMS OF DAYS.  ALSO,
        WHO KNOWS WHAT THE CUSTOMERS  ULTIMATE  BUSINESS  RULES  WILL  BE
        REGARDING PICKUP AND DELIVERY.  */

         start_date = due_date.

         shipfrom_date = start_date - transport_lt.
         {mfhdate.i shipfrom_date -1 shipfrom_site}

         shipto_date = start_date.
         {rchdate.i shipto_date -1 shipto_site}

         i = 0.
         do while shipfrom_date + transport_lt <> shipto_date
/*FT88*  and i < 14: */
/*H0Z5** /*FT88*/ and i < 31: */
/*H0Z5*/ and i < 365:
/*GUI*/ if global-beam-me-up then undo, leave.

            i = i + 1.

            start_date = start_date - 1.

            shipfrom_date = start_date - transport_lt.
            {mfhdate.i shipfrom_date -1 shipfrom_site}

            shipto_date = start_date.
            {rchdate.i shipto_date -1 shipto_site}
         end.
/*GUI*/ if global-beam-me-up then undo, leave.


/*J3PK*/ /* TO CALCULATE SHIPFROM DATE AND SHIPTO DATE BY NOT INCLUDING */
/*J3PK*/ /* SATURDAY AND SUNDAY IN THE DATE CALCULATION                 */
/*J3PK*/ if transport_lt > 0 and
/*J3PK*/    l_inc_wkend_shpcal = no then
/*J3PK*/ do:
/*J3PK*/    assign
/*J3PK*/       start_date     = due_date
/*J3PK*/       shipto_date    = start_date
/*J3PK*/       l_transport_lt = transport_lt
/*J3PK*/       l_temp_date    = start_date.

/*J3PK*/    do while l_transport_lt > 0:
/*J3PK*/       l_temp_date = l_temp_date - 1.

/*J3PK*/       /* IF THE DATE CALCULATED IS A SAT/SUN, SUBTRACTING BY 1 */
/*J3PK*/       do while weekday (l_temp_date) = 7 or
/*J3PK*/                weekday (l_temp_date) = 1:
/*J3PK*/          l_temp_date = l_temp_date - 1.
/*J3PK*/       end. /* DO WHILE WEEKDAY .. */

/*J3PK*/       l_transport_lt = l_transport_lt - 1.
/*J3PK*/    end. /* DO WHILE L_TRANSPORT_LT > 0 */

/*J3PK*/    if l_transport_lt = 0 then
/*J3PK*/       shipfrom_date = l_temp_date.

/*J3PK*/    /* TO CHECK IF SHIPFROM SITE IS OPEN ON THE SHIPFROM DATE */
/*J3PK*/    {mfhdate.i shipfrom_date -1 shipfrom_site}

/*J3PK*/    /* TO RE-CALCULATE SHIPTO DATE WHEN SHIPFROM DATE IS ADJUSTED */
/*J3PK*/    /* DUE TO SITE CALENDAR */
/*J3PK*/    if l_temp_date <> shipfrom_date then
/*J3PK*/    do:
/*J3PK*/       shptodtcal:
/*J3PK*/       repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

/*J3PK*/          assign
/*J3PK*/             l_temp_date    = shipfrom_date
/*J3PK*/             l_transport_lt = transport_lt.

/*J3PK*/          do while l_transport_lt > 0:
/*J3PK*/             l_temp_date = l_temp_date + 1.

/*J3PK*/             /* IF THE DATE CALCULATED IS A SAT/SUN, ADDING BY 1 */
/*J3PK*/             do while weekday (l_temp_date) = 7 or
/*J3PK*/                      weekday (l_temp_date) = 1:
/*J3PK*/                l_temp_date = l_temp_date + 1.
/*J3PK*/             end. /* DO WHILE WEEKDAY ... */

/*J3PK*/             l_transport_lt = l_transport_lt - 1.
/*J3PK*/          end. /* DO WHILE L_TRANSPORT_LT > 0 */

/*J3PK*/          if l_transport_lt = 0 then
/*J3PK*/             shipto_date = l_temp_date.

/*J3PK*/          /* TO CHECK IF CUSTOMER IS OPEN ON THE SHIPTO DATE */
/*J3PK*/          {rchdate.i shipto_date -1 shipto_site}

/*J3PK*/          /* IF THE CUSTOMER IS NOT OPEN, FIND SHIPFROM DATE AGAIN */
/*J3PK*/          /* AND CALCULATE NEW SHIPTO DATE                         */
/*J3PK*/          if l_temp_date <> shipto_date then
/*J3PK*/          do:
/*J3PK*/             shipfrom_date = shipfrom_date - 1.
/*J3PK*/             {mfhdate.i shipfrom_date -1 shipfrom_site}
/*J3PK*/             next shptodtcal.
/*J3PK*/          end. /* IF L_TEMP_DATE <> SHIPTO DATE */
/*J3PK*/          else
/*J3PK*/             leave shptodtcal.
/*J3PK*/       end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* REPEAT LOOP */

/*J3PK*/    end. /* IF L_TEMP_DATE <> SHIPFROM_DATE */

/*J3PK*/ end. /* IF TRANSPORT_LT > 0 */

         ship_date  = due_date.
/*N0RG*  ret_status = {&rcshipdt_p_1}. */
/*N0RG*/ {pxmsg.i &MSGNUM=4554 &ERRORLEVEL=1 &MSGBUFFER=ret_status}

/*FT88*  if i < 14 then do: */
/*H0Z5*  /*FT88*/ if i < 31 then do: */
/*H0Z5*/ if i < 365 then do:
            ship_date  = shipfrom_date.
            ret_status = "".
         end.

         ship_time = due_time.

         arrive_date = ship_date + transport_lt.
         arrive_time = due_time.
